package utility;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import android.widget.TextView;

//ReflectionUtils.java

public class ReflectionUtils {
  
  public static String getClassName(Object aClass){
    return aClass.getClass().getSimpleName();
  }
  
  // Tramite l'oggetto di cui non conosco la classe mi faccio restituire i suoi attributi in un array di stringhe
  
  public static String[] getStringFields(Object aClass) {
    Field[] campi = aClass.getClass().getDeclaredFields();
    String[] campiStringa = new String[campi.length];
    for (int i = 0; i < campi.length; i++) {
      campiStringa[i] = campi[i].getName();
    }
    return campiStringa;
  }
  
  public static void listMethodsUsingReflection() {

      //Obtain the Class instance
      Class tvClass = TextView.class;
      
      //Get the methods
 //     Method[] methods = tvClass.getDeclaredMethods();
      Method methods = tvClass.getEnclosingMethod();
      
      //Loop through the methods and print out their names
//      for (Method method : methods) {
//          System.out.println(method.getName());
//      }
      int i = 0;
      while(i < 10){
    	  System.out.println(methods.getName());
    	  i++;
      }
  }
}
